<?php
include('../../includes/classes/core.php');

header('Content-Type: application/json');

$start = $_REQUEST['start'];
$end   = $_REQUEST['end'];
$pord_name = $_REQUEST['prod_name'];

$quantity = array();
$date = array();
$name = array();

if($pord_name == 'საერთო ნავაჭრი' || $pord_name == ''){
			$res= mysql_query("SELECT 		'საერთო ნავაჭრი' AS `prod_name`,
					ROUND(SUM(sale_transaction_detail.product_quantity * sale_transaction_detail.cost),2) AS `quantity`,
					DATE(`sale_transaction`.`end_date`) AS `date`
					FROM sale_transaction
					JOIN sale_transaction_detail ON sale_transaction.id = sale_transaction_detail.transaction_id
					JOIN production ON production.id = sale_transaction_detail.production_id
					WHERE `sale_transaction`.`status`=0 AND DATE(`sale_transaction`.`end_date`) >= '$start' AND DATE(`sale_transaction`.`end_date`) <= '$end'
					GROUP BY DATE(`sale_transaction`.`end_date`)");
}else{
	$res= mysql_query("SELECT 		production.`name` AS `prod_name`,
			ROUND(SUM(sale_transaction_detail.cost * sale_transaction_detail.product_quantity),2) AS `quantity`,
			DATE(`sale_transaction`.`end_date`) AS `date`
			FROM sale_transaction
			JOIN sale_transaction_detail ON sale_transaction.id = sale_transaction_detail.transaction_id
			JOIN production ON production.id = sale_transaction_detail.production_id
			WHERE production.`name` = '$pord_name' AND `sale_transaction`.`status`=0 AND DATE(`sale_transaction`.`end_date`) >= '$start' AND DATE(`sale_transaction`.`end_date`) <= '$end'
			GROUP BY DATE(`sale_transaction`.`end_date`)");
}


while($row = mysql_fetch_assoc($res)){	
	$name[]     = $row['prod_name'];
	$quantity[] = (float)$row['quantity'];
	$date[] = $row['date'];
}



// $quantity = array(5,9);
// $date = array('01.03.2014', '01.03.2014');

 
$unit     = " ლარი";

$serie1[] = array('name' => $name[0], 'unit' => $unit, 'quantity' => $quantity, 'date' => $date);


echo json_encode($serie1);


?>